import matplotlib.pyplot as plt
import numpy as np

# 图像数据 二维数组形式显示像素值
def circle(x0,y0, r):
    # 坐标
    img = np.zeros((200,200))
    δ = 3-2*r
    x = 0; y = int(r)
    xy= lambda x,y:[( x+x0, y+y0),( x+x0,-y+y0),
                    (-x+x0, y+y0),(-x+x0,-y+y0),
                    ( y+x0, x+y0),( y+x0,-x+y0),
                    (-y+x0, x+y0),(-y+x0,-x+y0)]
    while x<=y:
        for xp,yp in xy(x, y):
            img[200-xp-1,yp] = 255
        if δ<0:
            δ += (4*x+6)
        else:
            δ += (4*(x-y)+10)
            y -= 1
        x += 1
    return img

img = circle(100,100, 50)

# 保存图像
plt.imsave("圆.png", img, cmap='gray_r')

# 显示图像
fig=plt.figure()
ax = fig.add_subplot(111)
ax.imshow(img, cmap='gray_r')
plt.show()